
//支持图片、字体等文件
// npm install --save-dev url-loader
// npm install --svae-dev file-loader


var config = {
	//...
	module: {
		rules: [
			//...
			{
				test: /\.(fig|jpg|png|woff|svg|eot|ttf)\??.*$/,
				loader: 'url-loader?limit=1024'
			}
		]
	}
}


// 打包 依赖
// npm install --save-dev webpack-merge
// npm install --save-dev html-webpack-plugin


// vue-router 的基本用法
// npm install --save vue-router

// main.js
import Vue from 'vue'
import VueRouter from 'vue-router'
import App from './app.vue'

Vue.use(VueRouter)


const Routes = [
	{
		path: '/index',
		meta: {
			title: '首页'
		}
		component: (resolve) = > require(['./views/index.vue], resolve)  //路由懒加载
		//component: require('./views/index.vue')			//一次性加载
	},
	
	{
		path: '/about',
		component: (rosolve) => require(['./views/about.vue'], resolve) 
		
	}
	{
		path: '*',
		redirect: '/index'		//找不到路径时，重定向到首页
	}
]

this.$router.replace('')
this.$router.push('/user/123')
this.$router.go(-1)
this.$router.go(2)

const router = new VueRouter(RouterConfig)
router.beforeEach((to, from, next) => {
	window.document.title = to.meta.title;		// 设置title
	next();	
})


router.afterEach((to, from, next) => {
	window.scrollTo(0, 0);		//进入页面后，滚动到某个位置
})

// 某页面需要验证登录，否则跳转到 登录页
router.beforeEach((to, from, next) => {
	if (window.localStorage.getItem('token')) {
		next();
	} else {
		next('/login')
	}
})











